package com.config;

import com.Interceptor.ConsumerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;


/**
 * Spring MVC支持
 *
 * @author 蔡文欣
 * @date 2023/06/24 09:00:09
 */
@Configuration
//当访问/js/？？？时候，走/js目录下的内容    设置对静态资源的访问放行
public class SpringMvcSupport extends WebMvcConfigurationSupport  {
    @Autowired
    private ConsumerInterceptor consumerInterceptor;
    /**
     * 添加资源处理程序
     *
     * @param registry 登记处
     */
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(consumerInterceptor).addPathPatterns("/goCart","/goCheckout","/goMyAccount");
    }
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("css/**").addResourceLocations("/css/");
        registry.addResourceHandler("js/**").addResourceLocations("/js/");
        registry.addResourceHandler("images/**").addResourceLocations("/images/");
        registry.addResourceHandler("fonts/**").addResourceLocations("/fonts/");
        registry.addResourceHandler("static/**").addResourceLocations("/static/");
    }

    /**
     * 配置缺省Servlet处理
     *
     * @param configurer 配置者
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {

        configurer.enable();
    }


}
